package cn.syy.controller.app;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.syy.pojo.domain.DriverAuthMaterial;
import cn.syy.pojo.dto.ChangeDriverLocationToGeoDto;
import cn.syy.pojo.dto.DriverDaySummaryDto;
import cn.syy.result.R;
import cn.syy.service.IDriverAuthMaterialService;
import cn.syy.service.IDriverService;
import com.aliyuncs.exceptions.ClientException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;


@Tag(name = "小程序司机对象",description = "小程序司机对象")
@RestController
@RequestMapping("/app/driver")
public class AppDriverController {

    @Autowired
    private IDriverService driverService;
    @Autowired
    private IDriverAuthMaterialService driverAuthMaterialService;
    /**
     * 小程序司机位置更新到Redis——Geo
     * */
    @Operation( summary= "小程序司机位置更新到Redis——Geo",description = "小程序司机位置更新到Redis——Geo接口")
    @PostMapping(value = "/changeLocationToGeo")
    public R<Void> changeLocationToGeo(@RequestBody ChangeDriverLocationToGeoDto changeDriverLocationToGeoDto) { //
        driverService.changeLocationToGeo(changeDriverLocationToGeoDto);
        return R.success();
    }
    /**
     * 小程序司机开始接单上线
     * */
    @Operation( summary= "小程序司机开始接单上线",description = "小程序司机开始接单上线接口")
    @PostMapping(value = "/online")
    public R<Void> online() { //  @NotNull :JSR303参数校验不为空
        driverService.online();
        return R.success();
    }
    /**
     * 小程序司机停止接单下线
     * */
    @Operation( summary= "小程序司机停止接单下线",description = "小程序司机停止接单下线接口")
    @PostMapping(value = "/offline")
    public R<Void> offline() { //  @NotNull :JSR303参数校验不为空
        driverService.offline();
        return R.success();
    }

    /**
     * 查询司机今日数据统计
     * @return
     */
    @Operation( summary= "查询司机今日数据统计",description = "查询司机今日数据统计接口")
    @GetMapping("/daySummary")
    public R<DriverDaySummaryDto> daySummary(){
        return R.success(driverService.daySummary());
    }

    /**
     * 查询司机实名信息审核结果
     * @return
     */

    @Operation( summary= "查询司机实名信息审核结果",description = "查询司机实名信息审核结果接口")
    @GetMapping("/realAuthInfo")
    public R<DriverAuthMaterial> realAuthInfo(){
        return R.success(driverService.realAuthInfo());
    }
    /**
     * 小程序司机注册
     * */
    @Operation( summary= "小程序司机实名认证",description = "小程序司机实名认证接口")
    @Parameter(name = "DriverAuthMaterial",description = "小程序司机真实信息",required = true)
    @PostMapping(value = "/saveRealAuth")
    public R<Void> saveRealAuth(@RequestBody @Valid DriverAuthMaterial driverAuthMaterial) { //  @NotNull :JSR303参数校验不为空
        driverAuthMaterialService.saveRealAuth(driverAuthMaterial);
        return R.success();
    }

    /**
     * 小程序司机注册
     * */
    @Operation( summary= "获取小程序Driver",description = "小程序司机对象获取接口")
    @Parameter(name = "openIdCode",description = "获取openId的code",required = true)
    @GetMapping(value = "register/{openCodeId}")
    @SaIgnore
    public R<Void> register(@PathVariable("openCodeId") @NotNull String openIdCode){ //  @NotNull :JSR303参数校验不为空
        driverService.register(openIdCode);
        return R.success();
    }

    /**
     * 小程序司机注册包含手机号
     * */
    @Operation( summary= "获取小程序Driver包含手机号",description = "小程序Driver包含手机号对象获取接口")
    @Parameter(name = "openIdCodeAndPhoneCode",description = "获取openId的code和获取手机号的code",required = true)
    @GetMapping(value = "register/{openCodeId}/{phoneCode}")
    @SaIgnore
    public R<Void> registerIncludePhoneCode(@PathVariable("openCodeId")String openIdCode ,@PathVariable("phoneCode") String phoneCode){ //  @NotNull :JSR303参数校验不为空
        driverService.registerIncludePhoneCode(openIdCode,phoneCode);
        return R.success();
    }

}
